﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.eLogistics;
using NetDon.OA.Portal.Common;
using NetDon.Utilities;

namespace NetDon.OA.Portal.eLogisticsQuery
{
    [Navigation("报表查询", "客服在途跟踪统计")]
    public partial class GoodsShippingStatusQueryPage : PageBase
    {
        protected int? CurrentOrderStatus { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                //    txtActualShippingDateStart.Text =
                //  TimeHelper.GetStartDayOfMonth().ToString("yyyy-MM-dd");
                //    txtActualShippingDateStart.Text =
                //TimeHelper.GetEndDayOfMonth().ToString("yyyy-MM-dd");
                txtActualShippingDateStart.Text =
DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtActualShippingDateEnd.Text =
    DateTime.Now.ToString("yyyy-MM-dd");


                txtActualDeliveredDateStart.Text =
DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtActualDeliveredDateEnd.Text =
    DateTime.Now.ToString("yyyy-MM-dd");
                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
             
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
            }
        }



        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

        }

        public void btnSearch_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["GoodsShippingStatusQuery"] = GetSearchCriteria();
            this.ScriptStartup("search();");
        }

        protected GoodsShippingStatusQueryCriteria GetSearchCriteria()
        {
            var criteria = new GoodsShippingStatusQueryCriteria
            {

            };
            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }
            DateTime? dateStart = null, dateEnd = null;
            if (!MiscUtilities.IsNullOrEmpty(txtActualShippingDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtActualShippingDateStart.Text.Trim());
            }
            if (!MiscUtilities.IsNullOrEmpty(txtActualShippingDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtActualShippingDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ActualShippingDate = new Range<DateTime?>(dateStart, dateEnd);

            }

            dateStart = null;
            dateEnd = null;
            if (!MiscUtilities.IsNullOrEmpty(txtActualDeliveredDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtActualDeliveredDateStart.Text.Trim());
            }
            if (!MiscUtilities.IsNullOrEmpty(txtActualDeliveredDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtActualDeliveredDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {

                criteria.ActualDeliveredDate = new Range<DateTime?>(dateStart, dateEnd);



            }

            if (!MiscUtilities.IsNullOrEmpty(ddlRouteTypeId.SelectedValue.ToGuid()))
            {
                criteria.RouteTypeId = ddlRouteTypeId.SelectedValue.ToGuid();
            }


            return criteria;
        }
        public void radioSummaryDate_CheckedChanged(object sender, EventArgs e)
        {

            var radioButton = (sender as RadioButton);
            if (radioButton.Checked)
            {
                if (radioButton.ID == "radioReceivingOrderDate")
                {
                    this.PanelCondition.Items["SummaryDate"].HeaderText = "出单日期";
                }
                if (radioButton.ID == "radioActualShippingDate")
                {
                    this.PanelCondition.Items["SummaryDate"].HeaderText = "实发货日期";
                }

            }

        }
    }


}